package org.slf4j; import java.util.Map; import org.slf4j.helpers.Util; import org.slf4j.impl.StaticMDCBinder; import org.slf4j.spi.MDCAdapter; public class MDC { static final String NO_STATIC_MDC_BINDER_URL = "http://www.slf4j.org/codes.html#no_static_mdc_binder"; static final String NULL_MDCA_URL = "http://www.slf4j.org/codes.html#null_MDCA"; static MDCAdapter mdcAdapter; static { try { mdcAdapter = StaticMDCBinder.SINGLETON.getMDCA(); } catch (NoClassDefFoundError e) { String message = e.getMessage(); if (!(message == null || message.indexOf("org/slf4j/impl/StaticMDCBinder") == -1)) { Util.reportFailure("Failed to load class \"org.slf4j.impl.StaticMDCBinder\"."); Util.reportFailure("See http://www.slf4j.org/codes.html#no_static_mdc_binder for further details."); } throw e; } catch (Exception e2) { Util.reportFailure("Could not bind with an instance of class [" + StaticMDCBinder.SINGLETON.getMDCAdapterClassStr() + "]", e2); } } private MDC() { } public static void clear() { if (mdcAdapter == null) { throw new IllegalStateException("MDCAdapter cannot be null. See also http://www.slf4j.org/codes.html#null_MDCA"); } mdcAdapter.clear(); } public static String get(String str) throws IllegalArgumentException { if (str == null) { throw new IllegalArgumentException("key parameter cannot be null"); } else if (mdcAdapter != null) { return mdcAdapter.get(str); } else { throw new IllegalStateException("MDCAdapter cannot be null. See also http://www.slf4j.org/codes.html#null_MDCA"); } } public static Map getCopyOfContextMap() { if (mdcAdapter != null) { return mdcAdapter.getCopyOfContextMap(); } throw new IllegalStateException("MDCAdapter cannot be null. See also http://www.slf4j.org/codes.html#null_MDCA"); } public static MDCAdapter getMDCAdapter() { return mdcAdapter; } public static void put(String str, String str2) throws IllegalArgumentException { if (str == null) { throw new IllegalArgumentException("key parameter cannot be null"); } else if (mdcAdapter == null) { throw new IllegalStateException("MDCAdapter cannot be null. See also http://www.slf4j.org/codes.html#null_MDCA"); } else { mdcAdapter.put(str, str2); } } public static void remove(String str) throws IllegalArgumentException { if (str == null) { throw new IllegalArgumentException("key parameter cannot be null"); } else if (mdcAdapter == null) { throw new IllegalStateException("MDCAdapter cannot be null. See also http://www.slf4j.org/codes.html#null_MDCA"); } else { mdcAdapter.remove(str); } } public static void setContextMap(Map map) { if (mdcAdapter == null) { throw new IllegalStateException("MDCAdapter cannot be null. See also http://www.slf4j.org/codes.html#null_MDCA"); } mdcAdapter.setContextMap(map); } }